<template>
	<view>
		<u-navbar height="50" back-icon-color="#333" 
			title="我的银行卡" title-color="#333" title-size="36"></u-navbar>
		<view class="content">
			<view class="cardView" v-for="(item,index) in bankItem" :key="index"  @click="select(item)" >
				<view class="cardTextView">
					<view class="cardTitle">{{item.bank}}</view>
					<view class="cardTitle">{{item.cardholder}}</view>
					<view class="cardText">{{item.bank_card_number}}</view>
				</view>
				<view class="unBandBtn" @click="onUnBand(item)">
					<text>解除绑定</text>
				</view>
			</view>
			<view class="addCard" @click="onAddBank()">+添加银行卡</view>
		</view>
	</view>
</template>

<script>
import { closeload, tiao, toastload } from '../../utils/common';
import {getCard} from '@/api/user.js'
	export default {
		data() {
			return {
				bankItem: []
			}
		},
		onShow() {
			this.initBank();
		},
		methods: {
			onClose() {
				uni.navigateBack({
					delta: 1
				});
			},
			initBank() {
				let self = this
				toastload()
				getCard().then(res => {
					closeload()
					self.bankItem = res.data;
				});
			},
			onUnBand(item) {
				tiao('/other/unband-card/unband-card?item=' + JSON.stringify(item));
			},
			onAddBank() {
				uni.navigateTo({
					url:'/other/add-card/add-card'
				})
				// tiao('/other/add-card/add-card');
			},
			select(item){
				// B页面传递：
				console.log(item);
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2]; //上一个页面
				let object={
				    number:item.bank_card_number,
				}
				prevPage.onShow(object);
				uni.navigateBack();
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
	}
	
	.cardView {
		display: flex;
		flex-direction: row;
		align-items: center;
		height: 240rpx;
		margin-top: 20rpx;
		margin-bottom: 20rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
		position: relative;
		background: linear-gradient(0deg, #248CFA, #33C9FF);
		border-radius: 10rpx;
	}
	
	.cardDataView {
		display: flex;
		flex-direction: row;
	}
	
	.cardIcon {
		width: 100rpx;
		height: 100rpx;
		margin-top: 40rpx;
		margin-left: 20rpx;
	}
	
	.cardTextView {
		flex: 1;
		display: flex;
		flex-direction: column;
		z-index: 10;
		margin-left: 20rpx;
	}
	
	.cardTitle {
		font-size: 30rpx;
		color: #FFFFFF;
		margin-bottom: 20rpx;
	}
	
	.cardText {
		font-size: 36rpx;
		color: #FFFFFF;
	}
	
	.addCard {
		text-align: center;
		background: #FFFFFF;
		box-shadow: 0px 1px 10px 0px rgba(153, 153, 153, 0.06);
		border-radius: 10rpx;
		font-size: 30rpx;
		color: #1977FF;
		margin-left: 30rpx;
		margin-right: 30rpx;
		margin-top: 30rpx;
		padding-left: 30rpx;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
	}
	
	.unBandBtn {
		width: 116rpx;
		height: 46rpx;
		line-height: 46rpx;
		text-align: center;
		background: rgba(255, 255, 255, 0.8);
		border-radius: 23rpx;
		font-size: 22rpx;
		font-weight: 400;
		color: #FF2B15;
		margin-right: 20rpx;
	}
	

	page {
		background: #F2F2F2;
	}
</style>
